package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TrustEnclosure;
import com.ruoyi.system.mapper.TrustEnclosureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HousingTrustMapper;
import com.ruoyi.system.domain.HousingTrust;
import com.ruoyi.system.service.IHousingTrustService;

/**
 * 房屋情况Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-06-16
 */
@Service
public class HousingTrustServiceImpl implements IHousingTrustService 
{
    @Autowired
    private HousingTrustMapper housingTrustMapper;
    @Autowired
    private TrustEnclosureMapper trustEnclosureMapper;

    /**
     * 查询房屋情况
     * 
     * @param htId 房屋情况ID
     * @return 房屋情况
     */
    @Override
    public HousingTrust selectHousingTrustById(Long htId)
    {
        return housingTrustMapper.selectHousingTrustById(htId);
    }

    /**
     * 查询房屋情况列表
     * 
     * @param housingTrust 房屋情况
     * @return 房屋情况
     */
    @Override
    public List<HousingTrust> selectHousingTrustList(HousingTrust housingTrust)
    {
        List<HousingTrust> housingTrusts = housingTrustMapper.selectHousingTrustList(housingTrust);
        for (int i = 0; i < housingTrusts.size(); i++) {
            TrustEnclosure trustEnclosure = new TrustEnclosure();
            trustEnclosure.setHtId(housingTrusts.get(i).getHtId());
            housingTrusts.get(i).setTrustEnclosures(trustEnclosureMapper.selectTrustEnclosureList(trustEnclosure));
        }
        return housingTrusts;
    }

    /**
     * 新增房屋情况
     * 
     * @param housingTrust 房屋情况
     * @return 结果
     */
    @Override
    public int insertHousingTrust(HousingTrust housingTrust)
    {housingTrust.setCreateTime(DateUtils.getNowDate());
        return housingTrustMapper.insertHousingTrust(housingTrust);
    }

    /**
     * 修改房屋情况
     * 
     * @param housingTrust 房屋情况
     * @return 结果
     */
    @Override
    public int updateHousingTrust(HousingTrust housingTrust)
    {housingTrust.setUpdateTime(DateUtils.getNowDate());
        return housingTrustMapper.updateHousingTrust(housingTrust);
    }

    /**
     * 批量删除房屋情况
     * 
     * @param htIds 需要删除的房屋情况ID
     * @return 结果
     */
    @Override
    public int deleteHousingTrustByIds(Long[] htIds)
    {
        return housingTrustMapper.deleteHousingTrustByIds(htIds);
    }

    /**
     * 删除房屋情况信息
     * 
     * @param htId 房屋情况ID
     * @return 结果
     */
    @Override
    public int deleteHousingTrustById(Long htId)
    {
        return housingTrustMapper.deleteHousingTrustById(htId);
    }
}
